/* util functions for setting URL values */
URL = {
	current:document.URL,
	toStruct:function(){
		URL.current = document.URL;
		var result = {};
		var urlSplit = URL.current.split('?');
		result.root = urlSplit[0]; // set the root path
		result.params = {};
		
		// set the arguments
		var args = "";
		if(urlSplit.length > 1){
			args = urlSplit[1];
		}
		var argSplit = args.split('&');
		for(var i = 0; i < argSplit.length; i++){
			if(argSplit[i].length > 1){
				var thisKey = "";
				var thisValue = "";
				var thisSplit = argSplit[i].split('=');
				thisKey = thisSplit[0];
				if(thisSplit.length > 1){
					thisValue = thisSplit[1];
				}
				result.params[thisKey] = thisValue;
			}
		}
		return result;
	},
	toURL:function(struct){
		var result = struct.root;
		for(var key in struct.params){
			if(result.indexOf('?') == -1){
				result += '?';
			} else {
				result += '&';
			}
			result = result + key;
			if(struct.params[key] != ""){
				result = result + '=' + struct.params[key];
			}
		}
		return result;
	},
	setValue:function(key,value,noCommit){
		var noCommit = noCommit || false;
		var value = value || "";
		var struct = URL.toStruct();
		struct.params[key] = value;
		URL.current = URL.toURL(struct);
		if(!noCommit){
			URL.set();
		}
		return URL.current;
	},
	removeValue:function(key,noCommit){
		var noCommit = noCommit || false;
		var struct = URL.toStruct();
		delete struct.params[key];
		URL.current = URL.toURL(struct);
		if(!noCommit){
			URL.set();
		}
	},
	set:function(target){
		var target = target || URL.current;
		try{
			window.history.pushState({},'',target);
		}catch(e){
			/*do nothing*/
		}
	}
};